package com.nowcoder;

import java.util.Scanner;

public class CountCharacter {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            char ch = scanner.nextLine().charAt(0);
            System.out.println(solver(str, ch));
        }
    }

    public static int solver(String str, char ch) {
        int len = str.length();
        int[] res = new int[256];
        for (int i = 0; i < len; i++) {
            res[str.charAt(i)]++;
        }
        if (isLowCase(ch)) {
            return res[ch] + res[ch - 32];
        }
        if (isHighCase(ch)) {
            return res[ch] + res[ch + 32];
        }
        return res[ch];
    }

    /**
     * 判断一个字符是否是字母[a,z], [A,Z]
     *
     * @param ch
     * @return
     */
    private static boolean isLowCase(char ch) {
        return 'a' <= ch && ch <= 'z';
    }

    private static boolean isHighCase(char ch) {
        return 'A' <= ch && ch <= 'Z';
    }
}
